import pjsua2 as pj
from ..src.client import GB28181Client

def main():
    client = GB28181Client()
    client.start()
    
    # 示例：请求实时视频
    client.request_live_video("34020000001320000001")
    
    # 示例：发送测试报警
    client.send_alarm("34020000001320000001", 1, "移动侦测报警")

# 模拟平台命令测试
def test_commands(client):
    # 测试目录查询
    catalog_cmd = """
    <Query>
        <CmdType>Catalog</CmdType>
        <SN>12345</SN>
        <DeviceID>3402000000</DeviceID>
    </Query>
    """
    client.sip_handler.on_rx_message("sip:server@example.com", catalog_cmd)
    
    # 测试PTZ控制
    ptz_cmd = """
    <Control>
        <CmdType>DeviceControl</CmdType>
        <SN>67890</SN>
        <DeviceID>34020000001320000001</DeviceID>
        <PTZCmd>A50F01</PTZCmd>
    </Control>
    """
    client.sip_handler.on_rx_message("sip:server@example.com", ptz_cmd)
    
    # 测试录像查询
    record_cmd = """
    <Query>
        <CmdType>RecordInfo</CmdType>
        <SN>112233</SN>
        <DeviceID>34020000001320000001</DeviceID>
        <StartTime>2023-01-01T00:00:00</StartTime>
        <EndTime>2023-01-01T12:00:00</EndTime>
    </Query>
    """
    client.sip_handler.on_rx_message("sip:server@example.com", record_cmd)

if __name__ == '__main__':
    main()
